home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Science / RLaB / examples / ode_err.r < prev    next >
Text File  |  1994-04-25  |  810b  |  48 lines

  1. #
  2. # Perform integration tests to determine the effect
  3. # of relerr, and abserr on the solution.
  4. #
  5.  
  6. vdpol = function ( t , x ) 
  7. {
  8.   local (xp)
  9.   xp = zeros(2,1);
  10.   xp[1] = x[1] * (1 - x[2]^2) - x[2];
  11.   xp[2] = x[1];
  12.   return xp;
  13. };
  14.  
  15. t0 = 0;
  16. tf = 10;
  17. x0 = [0; 0.25];
  18. dtout = 0.05;
  19.  
  20. relerr = [1e-6, 1e-5, 1e-4, 1e-3, 1e-2, 1e-1];
  21. abserr = relerr;
  22.  
  23. #
  24. # Baseline
  25. #
  26.  
  27. xbase = ode( vdpol, x0, 0, 20, 0.05, 1e-9, 1e-9);
  28. results = zeros (relerr.n, abserr.n);
  29. elapse = zeros (relerr.n, abserr.n);
  30.  
  31. "start testing loop"
  32. for (i in 1:abserr.n)
  33. {
  34.   xode.[i] = <<>>;
  35.   for (j in 1:relerr.n)
  36.   {
  37.     printf("\t%i %i\n", i, j);
  38.     tic();
  39.     xode.[i].[j] = ode( vdpol, x0, 0, 20, 0.05, relerr[j], abserr[i]);
  40.     elapse[i;j] = toc();
  41.  
  42.     # Save results
  43.     results[i;j] = max (max (abs (xode.[i].[j] - xbase)));
  44.   }
  45. }
  46.  
  47. results
  48.